package lab2;

public class NSpiral {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int n=4;
		int count=1;
		int[][] a = new int[n][n];
		for (int i = 0; i<n; i++)
		{
			a[0][i]=count++;
		}
		int go=2;
		while (go<2*n)
		{
			if (go==5) {
				a[1][1] = count ++;
			}
			for (int i = 1+go/5; i < n - go/4; i++)
			{
//				if (go%5==0) {
//					a[go/4][i-1] = count ++;
//				}
				if (go%4==1)
				{
					a[go/4][i] = count ++;
				}
				else if (go%4==2)
				{
					a[i][n-1-go/4] = count++;
				}
				else if (go%4==3)
				{
					a[n-1-go/4][n-1-i] = count++;
				}
				else
				{
					a[n-1-i][go/4-1] = count++;
				}
			}
			go++;
		}
		for (int i = 0; i<n; i++)
		{
			for (int j = 0; j<n; j++)
			{
				System.out.print(String.format("%02d",a[i][j]) + " ");
			}
			System.out.println();
		}
	}
}
